package com.xbongbong.saas.domain.dao;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import com.xbongbong.saas.domain.entity.WorkOrderFlowUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 *
 * @author 魏荣杰
 * @date 2019/3/11 16:36
 * @since v1.0
 * @version v1.0
 */
@Repository
@Mapper
public interface WorkOrderFlowUserDao {

    Integer insert(WorkOrderFlowUserEntity entity);

    Integer update(WorkOrderFlowUserEntity entity);

    List<WorkOrderFlowUserEntity> findEntitys(@Param("param") Map<String, Object> param);

    Integer getEntitysCount(@Param("param") Map<String, Object> param);

    /**
     * Description: 获取工单团队的userId
     * @param workOrderId 工单id
     * @param corpid 公司id
     * @param isMain 可为null,1主负责人 0协同人
     * @return java.util.List<java.lang.String>
     * @author 魏荣杰
     * @date 2019/5/24 9:57
     * @since v1.0
     */
    List<String> getTeamUserIdList(@Param("workOrderId") Long workOrderId, @Param("corpid") String corpid, @Param("isMain") Integer isMain);

    Integer delete(@Param("param") Map<String, Object> param);

    List<UserTeamEntity> findBaseEntitys(@Param("param") Map<String,Object> map);

    Integer batchDeleteByWorkOrderId(@Param("corpid") String corpid, @Param("workOrderIdIn") List<Long> dataIdList, @Param("userIdIn") List<String> userIdList);

    void insertBatch(@Param("list") List<WorkOrderFlowUserEntity> workOrderFlowUserEntityList);
    
    void insertBatchCK(@Param("list") List<WorkOrderFlowUserEntity> workOrderFlowUserEntityList);

    WorkOrderFlowUserEntity getByKey(@Param("key") Long key, @Param("corpid") String corpid);

    /**
     * Description: 获取工单团队主键id
     * @param workOrderId 工单id
     * @param corpid 公司id
     * @param isMain 可为null,1主负责人 0协同人
     * @return java.util.List<java.lang.Long>
     * @author 魏荣杰
     * @date 2019/5/24 9:58
     * @since v1.0
     */
    List<Long> getTeamIds(@Param("workOrderId") Long workOrderId, @Param("corpid") String corpid, @Param("isMain") Integer isMain);

    /**
     * Description: 根据用户id获取工单
     * @param corpid
     * @param userIds
     * @param isMain
     * @return java.util.List<java.lang.Long>
     * @author 魏荣杰
     * @date 2019/7/8 10:46
     * @since v1.0
     */
    List<Long> getWorkOrderIdByUserIdIn(@Param("corpid") String corpid, @Param("userIds") List<String> userIds, @Param("isMain") Integer isMain);

    void batchUpdateByIdIn(@Param("corpid")String corpid, @Param("idIn")List<Long> dataIdIn, @Param("isMain")Integer isMain, @Param("del")Integer del);

    List<WorkOrderFlowUserEntity> getUserListByWorkorderId(@Param("corpid") String corpid, @Param("id") Long id);

    void deleteBatchById(@Param("ids") List<Long> ids, @Param("corpid") String corpid, @Param("del")Integer del);

    Integer updateBatch(@Param("list") List<WorkOrderFlowUserEntity> list, @Param("corpid") String corpid);
}
